package com.xiaoshuidi.cloud.module.bpm.controller.app.swo;


import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.framework.common.pojo.PageResult;
import com.xiaoshuidi.cloud.framework.security.core.LoginUser;
import com.xiaoshuidi.cloud.module.bpm.controller.admin.sworecord.vo.GetSwoTicketRespVO;
import com.xiaoshuidi.cloud.module.bpm.controller.app.swo.vo.AppSwoTicketCreateReqVO;
import com.xiaoshuidi.cloud.module.bpm.controller.app.swo.vo.AppSwoTicketRespVO;
import com.xiaoshuidi.cloud.module.bpm.controller.app.swo.vo.SwoTicketAppraiseReqVO;
import com.xiaoshuidi.cloud.module.bpm.service.swo.SwoTicketService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static com.xiaoshuidi.cloud.framework.common.pojo.CommonResult.success;
import static com.xiaoshuidi.cloud.framework.security.core.util.SecurityFrameworkUtils.getLoginUser;
import static com.xiaoshuidi.cloud.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;


@Tag(name = "管理后台 - wo 服务工单申请")
@RestController
@RequestMapping("/bpm/app-swo-ticket")
@Validated
public class AppSwoTicketController {

    @Resource
    private SwoTicketService swoTicketService;

    @PostMapping("/create")
    @Operation(summary = "租客端 - 服务工单申请")
    public CommonResult<Long> appCreateSwoTicket(@Valid @RequestBody AppSwoTicketCreateReqVO appSwoTicketCreateReqVO) {
        Long userId = getLoginUserId();
        LoginUser loginUser = getLoginUser();
        return success(swoTicketService.appCreateSwoTicket(loginUser, appSwoTicketCreateReqVO));
    }

    @GetMapping("/page")
    @Operation(summary = "租客端 - 服务工单分页")
    public CommonResult<PageResult<AppSwoTicketRespVO>> appGetSwoTicketPage(@RequestParam("customerMobile") String customerMobile,
                                                                            @RequestParam("pageNo") Integer pageNo,
                                                                            @RequestParam("pageSize") Integer pageSize) {
        return success(swoTicketService.appGetSwoTicketPage(customerMobile, pageNo, pageSize));
    }

    @GetMapping("/get")
    @Operation(summary = "租客端 - 服务工单详情")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<GetSwoTicketRespVO> getSwoTicket(@RequestParam("id") Long id) {
        return success(swoTicketService.getSwoTicket(id));
    }

    @GetMapping("/cancel-swo-ticket")
    @Operation(summary = "租客端 - 取消服务工单")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<Boolean> appCancelSwoTicket(@RequestParam("id") Long id) {
        return success(swoTicketService.appCancelSwoTicket(getLoginUser(), id));
    }

    @PostMapping("/swo-ticket-appraise")
    @Operation(summary = "租客端 - 服务工单评价")
    public CommonResult<Boolean> swoTicketAppraise(@RequestBody @Valid SwoTicketAppraiseReqVO swoTicketAppraiseReqVO) {
        return success(swoTicketService.swoTicketAppraise(swoTicketAppraiseReqVO));
    }
}

